const {ccclass, property} = cc._decorator;

@ccclass
export default class Create_Label extends cc.Component {

    @property(cc.Node)
    canvas: cc.Node = null;

    @property({displayName: "文字预制体", tooltip: "文字预制体", type: cc.Prefab})
    label: cc.Prefab = null;

    // 创建新的文字专用函数
    create_new_label (str: string) {
        // 创建文字预制体
        let node = cc.instantiate(this.label);
        // 父节点为canvas
        node.parent = this.canvas;
        // 设置坐标
        node.position = cc.v3(0, 0);

        // 获取label
        let lb = node.children[0].getComponent(cc.Label);
        // 设置显示的内容
        lb.string = str;
    }

    /*
    如何使用？
        let s = cc.find("Canvas").getComponent("Create_Label");
        s.create_new_label("请输入内容");
    */
    

}
